const mysql = require('mysql2/promise');
require('dotenv').config();

// 数据库连接配置
const dbConfig = {
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  port: process.env.DB_PORT,
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0
};

// 创建不带数据库名的连接池（用于初始化）
const initPool = mysql.createPool(dbConfig);

// 创建带数据库名的连接池（用于应用）
const pool = mysql.createPool({
  ...dbConfig,
  database: process.env.DB_NAME
});

module.exports = {
  initPool,
  pool
}; 